package de.jmda.gen.java.impl;

import de.jmda.gen.GeneratorException;
import de.jmda.gen.java.MethodBodyGenerator;
import de.jmda.gen.java.MethodModifiersGenerator;
import de.jmda.gen.java.MethodNameGenerator;
import de.jmda.gen.java.MethodParametersGenerator;
import de.jmda.gen.java.ModifiersUtil;
import de.jmda.gen.java.DeclaredStaticMethodGenerator;
import de.jmda.gen.java.ThrowsClauseGenerator;
import de.jmda.gen.java.TypeNameGenerator;

public class DefaultDeclaredStaticMethodGenerator
		extends AbstractDeclaredMethodGenerator
		implements DeclaredStaticMethodGenerator
{
	public DefaultDeclaredStaticMethodGenerator(
      MethodModifiersGenerator modifiersGenerator,
      TypeNameGenerator typeNameGenerator,
      MethodNameGenerator methodNameGenerator,
      MethodParametersGenerator methodParameterListGenerator,
      ThrowsClauseGenerator throwsClauseGenerator,
      MethodBodyGenerator methodBodyGenerator)
  {
	  super(
	  		modifiersGenerator,
	  		typeNameGenerator,
	  		methodNameGenerator,
	      methodParameterListGenerator,
	      throwsClauseGenerator,
	      notNull(methodBodyGenerator));
	  
	  demandModifiersGenerator().setStatic(true);
  }

	public DefaultDeclaredStaticMethodGenerator()
  {
		this(null, null, null, null, null, null);
  }

	@Override
	public StringBuffer generate() throws GeneratorException
	{
		return validate(super.generate());
	}

	/**
	 * @param stringBuffer
	 * @return <code>stringBuffer</code>
	 * @throws GeneratorException if <code>stringBuffer</code> does not contain
	 *                            {@link ModifiersUtil#STATIC}
	 */
	protected StringBuffer validate(StringBuffer stringBuffer)
			throws GeneratorException
	{
		if (false == ModifiersUtil.hasStaticModifier(stringBuffer))
		{
			throw new GeneratorException(
					stringBuffer + " has to contain [" + ModifiersUtil.STATIC + "] " +
					"modifier");
		}
		
		return stringBuffer;
	}
}